var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: 0,
    userInfo: {},
    phone:'',

    order1:getApp().globalData.baseurl+'/static/order1.png',
    order2:getApp().globalData.baseurl+'/static/order2.png',
    order3:getApp().globalData.baseurl+'/static/order3.png',
    order4:getApp().globalData.baseurl+'/static/order4.png',

    amount:getApp().globalData.baseurl+'/static/amount.png',
    score:getApp().globalData.baseurl+'/static/score.png',
    check:getApp().globalData.baseurl+'/static/check.png',


    about:getApp().globalData.baseurl+'/static/about.png',
    feedback:getApp().globalData.baseurl+'/static/feedback.png',
    kefu:getApp().globalData.baseurl+'/static/kefu.png',

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  feedback(){
    wx.navigateTo({
      url: '/pages/mine/feedback',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    let res = wx.getWindowInfo()
    this.setData({
      statusBarHeight: res.statusBarHeight,
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    wx.showShareMenu({
      withShareTicket:true,
      menus:['shareAppMessage','shareTimeline']
    })
    console.log(app.globalData.userInfo);
    if(app.globalData.userInfo==null){
      this.getUserInfo();
    }else{
      this.user_info(app.globalData.userInfo.id);
      this.kefu();
    }
    getApp().globalData.nav = 0

  },

  //获取用户信息
  getUserInfo: function(o) {
		var e = this;
		wx.login({
			success: function(a) {  
        wx.request({
					url: app.globalData.httpUrl+"api/mini/getOpenid",
					header: {
						'content-type': 'application/x-www-form-urlencoded','appid':app.globalData.appId
					},
					method: 'POST',
					dataType: 'json',
					data: {
						code: a.code
					},
					success: function(re) {
						var openid = 	re.data.data.openid;
						wx.hideLoading() ;
						console.log("openid信息",openid ), getApp().getOpenId = openid,
							wx.request({
								url: app.globalData.httpUrl+"api/mini/getwechatuser",
								data: {
									openid: openid
								},
								header: {
									'content-type': 'application/x-www-form-urlencoded','appid':app.globalData.appId
								},
								method: 'POST',
								dataType: 'json',
								success: function(a) { 
                  app.globalData.userInfo = a.data.data;
                  e.kefu();
                  e.user_info(app.globalData.userInfo.id);            
								}
							});
					},
					fail: function(a) {},
					complete: function(a) {}
				});
			}
		});
  },
  renzheng(){
    wx.navigateTo({
      url: '/pages/setting/addr'
    })
  },
  score_action(){
    wx.navigateTo({
      url: '/pages/mine/score_log'
    })
  },

  check_action(){
    wx.navigateTo({
      url: '/pages/report/index'
    })
  },

  amount_action(){
    wx.navigateTo({
      url: '/pages/mine/recharge'
    })
  },

  //用户
  user_info:function(id){
    var that = this;
    wx.request({
      url: app.globalData.httpUrl+"api/mini/user_info",
      header: {
          'content-type': 'application/x-www-form-urlencoded','appid':app.globalData.appId
      },
      method: 'POST',
      data:{'id':id},
      dataType: 'json',
      success: function (res) {
        console.log(res);
          that.setData({
            find:res.data
          })
          app.globalData.userInfo = res.data;
          that.setData({
            userInfo:app.globalData.userInfo,
          })
      }
    })
  },

  //客服电话
  kefu:function(){
    var that = this;
    wx.request({
      url: app.globalData.httpUrl+'/api/mini/kefu',
      data:{id:app.globalData.userInfo.id},
      header: {
        'content-type': 'application/x-www-form-urlencoded','appid':app.globalData.appId
      },
      method: 'POST',
      dataType: 'json',
      success (res) { console.log(res);
         that.setData({
           tel:res.data
         })
      }
    })
  },
  order(e){
    var i = e.currentTarget.dataset.i
    wx.navigateTo({
      url: '/pages/order/index?i='+i,
    })
  },
  //协议
  xieyi:function(){
    wx.navigateTo({
      url: '/pages/xieyi/xieyi',
    })
  },
  //电话
  tel:function(){
    wx.makePhoneCall({
      phoneNumber: this.data.tel
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})